﻿using System;
using System.Web.UI;
using System.Web.Services;
using System.Linq;
using System.Collections.Generic;
using System.Web;

namespace DynaBoard
{
    public partial class BoardPage : Page
    {
        protected int boardId;
        protected string boardName;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.boardId = int.Parse(Request.QueryString["id"]);
                this.boardName = Board.NameFromId(this.boardId);
            }
            catch (ArgumentException)
            {
                return;
            }
        }

        [WebMethod]
        public static int StartThread(int board, string authorName, string authorEmail, string subject, string body)
        {
            return Post.StartThread(board, authorName, authorEmail, subject, body, new RequestorAddress());
        }

        [WebMethod(CacheDuration = 30)]
        public static Thread[] FetchLatestPosts(int boardId)
        {
            return Post.FetchLatestFromBoard(boardId, 20);
        }

        [WebMethod(CacheDuration = 30)]
        public static object[] MostActive()
        {
            return Post.MostActive(new TimeSpan(12, 0, 0), 10);
        }
    }
}
